package wzc.design_pattern.behaviour.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author 那和不是个啥
 * @Date 2025/7/20
 * @Description
 */

public class WeatherStation implements Subject {
    private final List<Observer> observers = new ArrayList<>();
    private String weather;
    @Override
    public void registerObserver(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void removeObserver(Observer observer) {
        observers.remove(observer);
    }

    @Override
    public void notifyObservers() {
        observers.forEach(observer -> observer.update(weather));
    }

    public void setWeather(String weather) {
        this.weather = weather;
        notifyObservers();
    }
}
